<?php
/**
 * 房源纠错
 */

namespace app\badmin\model;


use app\common\lib\RespCode;
use app\common\model\BaseModel;
use custom\Err;

class HouseErr extends BaseModel {

    /**
     * 添加
     * @param $params
     * @return bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public static function add($params) {
        $house = db('house')
            ->where('is_shelf', 1)
            ->where('id', $params['house_id'])
            ->find();
        if (empty($house)) {
            Err::add('房源不存在', RespCode::PARAMS_ERR);
            return false;
        }
        if (empty(trim($params['content']))) {
            Err::add('请输入内容', RespCode::PARAMS_ERR);
            return false;
        }
        if (mb_strlen(trim($params['content'])) > 100) {
            Err::add('字数请控制住100字以内', RespCode::PARAMS_ERR);
            return false;
        }
        $data = [
            'company_id' => $params['company_id'],
            'house_id'   => $params['house_id'],
            'content'    => $params['content'],
            'status'     => 0,
            'itime'      => time(),
        ];
        self::insert($data);
        return true;
    }

}